package com.example.itshome.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.bumptech.glide.Glide;
import com.example.itshome.R;
import com.example.itshome.impl.ViewOutlineProviderImpl;
import com.example.itshome.entity.OrganizationEntity;

import java.util.List;

public class JoinedOrganizationRecycleViewAdapter extends RecyclerView.Adapter<JoinedOrganizationRecycleViewAdapter.JoinedOrganizationViewHolder> {

    private final List<OrganizationEntity> mData;
    private final Context context;

    public JoinedOrganizationRecycleViewAdapter(Context context,List<OrganizationEntity> list){
        mData=list;
        this.context=context;
    }

    @NonNull
    @Override
    public JoinedOrganizationViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view=View.inflate(context, R.layout.recycle_joined_organization_page_item,null);
        view.setOutlineProvider(new ViewOutlineProviderImpl(20));
        view.setClipToOutline(true);
        JoinedOrganizationViewHolder holder=new JoinedOrganizationViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull JoinedOrganizationViewHolder holder, int position) {
        OrganizationEntity entity=mData.get(position);
        holder.nameTextView.setText(entity.name);
        holder.timeTextView.setText(entity.joinDate);

        Glide.with(context).load(entity.pictureSrc).placeholder(R.drawable.sample_picture).into(holder.imageView);
    }

    @Override
    public int getItemCount() {
        return mData.size();
    }

    static class JoinedOrganizationViewHolder extends RecyclerView.ViewHolder {
        ImageView imageView;
        TextView nameTextView;
        TextView timeTextView;
        public JoinedOrganizationViewHolder(@NonNull View itemView) {
            super(itemView);
            imageView=itemView.findViewById(R.id.imv_recycle_join_organization_image);
            nameTextView=itemView.findViewById(R.id.txv_recycle_joined_organization_name);
            timeTextView=itemView.findViewById(R.id.txv_recycle_joined_organization_time);
            imageView.setOutlineProvider(new ViewOutlineProviderImpl(20));
            imageView.setClipToOutline(true);
        }
    }
}
